//package com.xiaoxu.intranetweb.config;
//
//import org.springframework.context.annotation.Configuration;
//import org.springframework.messaging.Message;
//import org.springframework.messaging.MessageChannel;
//import org.springframework.messaging.simp.config.ChannelRegistration;
//import org.springframework.messaging.simp.config.MessageBrokerRegistry;
//import org.springframework.messaging.simp.stomp.StompCommand;
//import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
//import org.springframework.messaging.support.ChannelInterceptor;
//import org.springframework.web.servlet.config.annotation.CorsRegistry;
//import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
//import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
//import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
//
//import java.util.Arrays;
//
//@Configuration
//@EnableWebSocketMessageBroker
//public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
//    @Override
//    public void configureMessageBroker(MessageBrokerRegistry config) {
//        config.enableSimpleBroker("/topic","/user"); // 配置消息代理，将消息发送到以"/topic"群发，群发的前缀是"/topic"，点对点的前缀是"/user"
//        config.setApplicationDestinationPrefixes("/app"); // 设置消息的前缀，用于区分普通消息和订阅消息
//
//    }
//    @Override
//    public void registerStompEndpoints(StompEndpointRegistry registry) {
//        registry.addEndpoint("/websocket") // 注册一个WebSocket端点，客户端就可以通过该端点与服务器建立连接
//                  .setAllowedOrigins("http://localhost:5173","http://192.168.1.106:5174","http://192.168.1.106:8083","http://192.168.1.111:8088") // 允许跨域
//                .withSockJS();// 支持SockJS协议
////        支持stomp协议
//
//    }
//
//
//
//    @Override
//    public void configureClientInboundChannel(ChannelRegistration registration) {
//        registration.interceptors(new ChannelInterceptor() {
//            @Override
//            public void postSend(Message<?> message, MessageChannel channel, boolean sent) {
//                StompHeaderAccessor sha = StompHeaderAccessor.wrap(message);
//                // check if SEND message
//                if (sha.getCommand() == StompCommand.SEND) {
//                    // check if message is sent successfully
//                    if (sent) {
//                    } else {
//                    }
//                }
//            }
//        });
//    }
//
//}